import { createApp, type App } from 'vue'
import './style.css'
import ElApp from './App.vue'
/**
 * 配置qiankun
 */
import {
    renderWithQiankun,
    qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";
// 定义空对象
export interface EmptyObj {
    container?: HTMLElement
    [key: string]: any;
}

let instance: App
const render = (props: EmptyObj) => {

    instance = createApp(ElApp)
    let { container } = props

    instance.mount(container ? container.querySelector('#app') : '#app')
}
const initQianKun = () => {
    renderWithQiankun({
        mount(props) {
            console.log("%c", "color:green;", " ChildOne mount");
            render(props);
        },
        bootstrap() {
            console.log("%c", "color:green;", " ChildOne bootstrap");
        },
        update() {
            console.log("%c", "color:green;", " ChildOne update");
        },
        unmount(props: any) {
            console.log("unmount", props);
            instance.unmount();
            if (instance._container) {
                instance._container.innerHTML = "";
            }
        },
    });
};
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
    console.log("qiankun渲染开始");
    initQianKun();
} else {
    console.log("不是qiankun渲染");
    render({});
}
